/**
 * 
 */
package com.whu.waterworks.impl;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate4.HibernateTemplate;


import com.whu.waterworks.dao.QualityNormolDao;
import com.whu.waterworks.model.QualityNormol;

/**
 * @author： Joymin
 * @date：2016-4-2 下午4:21:37
 * 说明: 
 */
public class QualityNormolDaoImpl implements QualityNormolDao {

	private HibernateTemplate hibernateTemplate;
	
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNormolDao#saveQualityNormol(com.whu.waterworks.model.QualityNormol)
	 */
	@Override
	public boolean saveQualityNormol(QualityNormol norm) {
		// TODO Auto-generated method stub
		hibernateTemplate.save(norm);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNormolDao#updateQualityNormol(com.whu.waterworks.model.QualityNormol)
	 */
	@Override
	public boolean updateQualityNormol(QualityNormol norm) {
		// TODO Auto-generated method stub
		hibernateTemplate.merge(norm);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNormolDao#delQualityNormol(com.whu.waterworks.model.QualityNormol)
	 */
	@Override
	public boolean delQualityNormol(QualityNormol norm) {
		// TODO Auto-generated method stub
		hibernateTemplate.delete(norm);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNormolDao#getLimitedQualityNormol()
	 */
	@Override
	public QualityNormol getLimitedQualityNormol() {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		ArrayList<QualityNormol> rs =(ArrayList<QualityNormol>) hibernateTemplate.find("from QualityNormol _QualityNormol where _QualityNormol.type='1'");
		if(null!=rs && rs.size()>0){
			return rs.get(0);
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNormolDao#getQualityNormolByIdAndTime(java.lang.String, java.lang.String)
	 */
	@Override
	public List<QualityNormol> getQualityNormolByIdAndTime(String waterPlantId,
			String time) {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		ArrayList<QualityNormol> rs =(ArrayList<QualityNormol>) hibernateTemplate.find("" +
				"from QualityNormol _QualityNormol where _QualityNormol.waterplantId='"+waterPlantId+"' and _QualityNormol.time='"+time+"'");
		if(null!=rs && rs.size()>0){
			return rs;
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.QualityNormolDao#getQualityNormolById(java.lang.String)
	 */
	@Override
	public QualityNormol getQualityNormolById(String id) {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		ArrayList<QualityNormol> rs =(ArrayList<QualityNormol>) hibernateTemplate.find("from QualityNormol _QualityNormol where _QualityNormol.id='"+id+"'");
		if(null!=rs && rs.size()>0){
			return rs.get(0);
		}
		return null;
	}

	//zhoululu
		@Override
		public List<QualityNormol> getQualityNormols(String code, String starttime,String endtime) {
			//SimpleDateFormat ft=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
			@SuppressWarnings("unchecked")
			ArrayList<QualityNormol> qns=(ArrayList<QualityNormol>) hibernateTemplate.find(
					"from QualityNormol qn where qn.waterplantId='"+code+"' and qn.time between '"+
							starttime+"' and '"+endtime+"'");
			return qns;
		}	
	
}
